package com.softme.trade.control;

import javax.faces.context.FacesContext;
import javax.servlet.RequestDispatcher;

import org.springframework.stereotype.Controller;

import com.softme.trade.i18n.I18nUtils;
import com.softme.trade.view.util.FacesUtil;

@Controller("loginController")
public class LoginController
{

	public LoginController()
	{
	}

	public String logar()
	{
		try
		{
			RequestDispatcher dispatcher = FacesUtil.getServletRequest().getRequestDispatcher(
					"/j_spring_security_check");
			dispatcher.forward(FacesUtil.getServletRequest(), FacesUtil.getServletResponse());
			FacesContext.getCurrentInstance().responseComplete();
		}
		catch (Exception ex)
		{
			FacesUtil.showErrorMessage(ex.getMessage());
			return null;
		}
		return null;
	}

	public String logout()
	{
		try
		{
			RequestDispatcher dispatcher = FacesUtil.getServletRequest().getRequestDispatcher(
					"/j_spring_security_logout");
			dispatcher.forward(FacesUtil.getServletRequest(), FacesUtil.getServletResponse());
			FacesContext.getCurrentInstance().responseComplete();
			
		}
		catch (Exception ex)
		{
			FacesUtil.showErrorMessage(I18nUtils.getString("errorLogOut"));
			ex.printStackTrace();
		}
		return null;
	}

}
